(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI PathFileExists Function
Checks if the specified file or folder exists.
Scope
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
Syntax
function PathFileExists(pszPath : LPCSTR) : BOOL;
Parameters
pszPath [in] A pointer to a zero terminated string that specifies the path and name of the file system object (typically file or folder) of interest. This string, including the terminating NULL character, should/may not exceed NAX_PATH (= 260) characters in length.
Return Values
If the function was able to confirm the existence of the file system object, it returns TRUE, if not, FALSE.
Remarks
This function provides the same functionality as the Delphi, SysUtils and FileCtrl units, FileExists and DirectoryExists functions.
If the function fails when called with a fully qualified path beyond the drive root (as in the example(s), below), the Windows API function GetLastError will generally only return error code 2 (ERROR_FILE_NOT_FOUND). However, at the time of publication of this document (September 2016) we had not yet tested it with paths restricted to the root and UNC, server\share paths.
The function appears to determine the existence of the file system object using the same function as the Delphi, FileCtrl DirectoryExists function, namely, GetFileAttributes.
Example
PROCEDURE TForm4.TestShlWAPIPathFileExists(Sender : TObject); VAR nametovrify : STRING; VAR apiretval : BOOL; VAR newinfoline : STRING; BEGIN nametovrify := ''; apiretval := FALSE; newinfoline := ''; nametovrify := 'C:\Windows\System32\Shell32.dll'; newinfoline := 'PathFileExists called with ' + nametovrify; Memo1.Lines.Add(newinfoline); apiretval := PathFileExists(PChar(nametovrify)); IF apiretval THEN newinfoline := 'returned TRUE' ELSE newinfoline := 'returned FALSE'; Memo1.Lines.Add(newinfoline); nametovrify := 'C:\Windows\System32\DummyFolderName.xls'; newinfoline := 'PathFileExists called with ' + nametovrify; Memo1.Lines.Add(newinfoline); apiretval := PathFileExists(PChar(nametovrify)); IF apiretval THEN newinfoline := 'returned TRUE' ELSE BEGIN newinfoline := 'returned FALSE'; exterrorcode := INTEGER(GetLastError()); newinfoline := newinfoline + ' GetLastError provided the additional error info : ' + IntToStr(exterrorcode); END; Memo1.Lines.Add(newinfoline); Memo1.Lines.Add(''); END;
Provided Windows was installed under C:\Windows, and you have not added a file or folder named "DummyFolderName.xls" to the System32 folder, the above example ought to produce the following output:
PathFileExists called with C:\Windows\System32\Shell32.dll returned TRUE PathFileExists called with C:\Windows\System32\DummyFolderName.xls returned FALSE GetLastError provided the additional error info : 2
Requirements
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (PathFileExists and PathFileExistsA) and Unicode (PathFileExistsW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71
Min. ShlWAPI.dll version based on SST research: 4.71
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later
See Also
PathFindOnPath, PathIsDirectory, PathIsSystemFolder.
 
Windows APIs: PathFileExists, PathIsDirectory PathIsRooty PathAddExtension.


Document/Contents version 1.01
Page/URI last updated on 07.12.2023
 
Copyright © Stoelzel Software Technologie (SST) 2010 - 2022
Suggestions and comments mail to:
webmaster@stoelzelsoftwaretech.com